<?php
$this->sendDebugMessage("joinTable model start");
$tid = $data->para->tableID;
$rid = $this->userCenter->userList[$ip]->roomID;
//向游戏桌的其他玩家发送有新玩家进来
$tb = $this->userCenter->roomList[$rid]->tableList[$tid];
$sl = $tb->seatList;
$ul = array();
$nextSeatID = "";

for($i=0;$i<$tb->maxUserNum;$i++)
{
	$si = $i + 1;
	if(isset($sl[$si]))
	{
		if($sl[$si]->userID!=$ip)
		{
			array_push($ul,$sl[$si]->userID);
		}
	}else if(empty($nextSeatID)){
		$nextSeatID = strval($si);
	}
}

if(empty($nextSeatID))
{
	//游戏桌已满
}
$st=new Seat();
$st->seatID = $nextSeatID;
$st->userID = $ip;

$this->userCenter->userList[$ip]->seatID = $nextSeatID;
$this->userCenter->userList[$ip]->tableID = $tid;

$tb->seatList[$st->seatID]=$st;

$response = new Response();
$response->event = "SE_JOIN_TABLE_UPDATE";
$response->body = '{"seat":'.$st.',"tableID":"'.$tid.'"}';
$this->broadcastGroup($response,$this->userCenter->roomList[$rid]->userList,array($ip));

//向自已发送进入游戏桌成功信息
$response = new Response();
$response->event = "SE_JOIN_TABLE_SUCCESS";
$response->body = $this->userCenter->roomList[$rid]->tableList[$tid]->getDetail();
$this->sendData($ip,$response , true );
$this->sendDebugMessage("joinTable model end");
